<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Me
 *
 * @property int $id
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property string|null $deleted_at
 * @property int $is_one
 *
 * @package App\Models
 */
class Me extends Model
{
    use SoftDeletes;

    protected $with = ['articles'];
    protected $withCount = ['articles'];
    protected $table = 'me';

    protected $casts = [
        'is_one' => 'int'
    ];

    protected $fillable = [
        'is_one'
    ];

    protected static function boot()
    {
        parent::boot();

        Me::creating(function ($model) {
            $model->is_one = Me::max('id') + 1;
        });
    }

    public function articles()
    {
        return $this->hasMany(MeArticle::class, 'me_id');
    }
}
